开发服务
easywebpack 整个体系提供的开发构建服务是基于 koa 实现的,用于支持各种类型项目(服务端渲染,前端渲染,静态页面,本地内存编译等),实现了 内存编译,热更新,发布编译,[代理](https://webpack.js.org/configuration/dev-server/#devserver-proxy),[historyApiFallback](https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback)等功能,其中代理和historyApiFallback配置只在纯前端项目起作用。具体实现请见 [webpack-tool ](https://github.com/easy-team/webpack-tool)插件。 easywebpack-cli 和 [egg-webpack](https://github.com/easy-team/egg-webpack) 都依赖该插件。
koa-webpack-hot-middleware
koa-webpack-dev-middleware
koa-history-api-fallback: https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback
http-proxy: https://webpack.js.org/configuration/dev-server/#devserver-proxy
webpack
纯前端渲染项目
//${root}/webpack.config.js
module.exports = {
entry:{
index: './src/index.js'
},
module:{
rules:[]
}
plugins: [],
devServer: {
open: 'http://127.0.0.1:8888',
// https://webpack.js.org/configuration/dev-server/#devserver-before
before: before => {
// register koa middleware
},
// https://webpack.js.org/configuration/dev-server/#devserver-after
after: app => {
// register koa middleware
},
// https://webpack.js.org/configuration/dev-server/#devserver-proxy
proxy: {
'/api': {
target: 'http://localhost:3000',
pathRewrite: {'^/api' : ''}
}
},
// https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback
historyApiFallback: {
index: '/app.html' // 默认 index.html
}
}
}
服务端渲染项目
Egg 服务端渲染项目时,devServer 配置是无需的,即使配置了也无效。代理和historyApiFallback通过项目的 Node 服务处理。